package com.projectpractice.service;


import com.projectpractice.bean.Classify;
import com.projectpractice.bean.User;
import com.projectpractice.common.utils.Md5Util;
import com.projectpractice.repository.ClassifyRepository;
import com.projectpractice.repository.UserRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Optional;

//@Service 注解 ：UserServiceImpl如果打上@Service，
// 在Spring启动的时候，会被扫描到Spring容器中，组件被Spring容器所管理。
@Service
public class ClassifyServiceImpl implements ClassifyService {

    @Autowired
    ClassifyRepository classifyRepository;

    @Override
    public List<Classify> getClassify() {
        return classifyRepository.findAll();
    }

    @Override
    public int delete(Integer cid) {
        try{
            classifyRepository.deleteById(cid);
        } catch (Exception e) {
            return 0;
        }
        return 1;
    }

    @Override
    public Classify addClassify(Classify classify) {
        return classifyRepository.save(classify);
    }

    @Override
    public Classify getClassifyByCid(Integer id) {
        return classifyRepository.getClassifyByCid(id);
    }

    @Override
    public Classify getClassifyByCla(String classify) {
        return classifyRepository.getClassifyByCla(classify);
    }
}

